package com.tt.controller;

import com.tt.pojo.User;
import com.tt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
public class LoginController {
    @Autowired
    UserService userService;


    @RequestMapping("go_login.html")
    public String goLogin() {
        return "login";
    }

    @RequestMapping("login.html")
    public String login(User user) {
        //判断是否是管理员
        if(user.getRole()==1){
            User user1=userService.getUserByName(user.getUsername());
            if(user1==null){
                System.out.println("没有此用户");
                return "login";
            }else{
                if(!user.getPassword().equals(user1.getPassword())){
                    return "login";
                }else{
                    return "/admin/index";
                }
            }

        }
        return  null;
    }
    @RequestMapping("out.html")
    public String outLogin(){
        System.out.println("退出系统");
        return "redirect:go_login.html";
    }

}
